﻿using System;
using System.ComponentModel;
using DoradoFramework.Core;
using Eflong.Config;
using Eflong.Utility;

namespace Eflong.Tasks
{
    [Description( "KJLAII转储任务" )]
    internal class KJLAIITask : TaskTemplate<KJLAIITask>
    {
        public override bool Enabled
        {
            get
            {
                return true;
            }
            set
            {
                _enabled = value;
            }
        }

        public KWBridgeConfig KWConfig
        {
            get { return KWBridgeConfig.Instance; }
        }

        /// <summary>
        /// 创建内存定时回收任务
        /// </summary>
        protected override bool CreateTask( )
        {
            if ( KWConfig.KJSysParas.KJType.ToUpper( ) == "KJLAII" )
            {
                if ( TaskHandle == null )
                {
                    TaskHandle = GlobalTimer<ITask>.Default.Add( TimeSpan.FromSeconds( 5 ) , new TaskFuncAdapter( ( ) =>
                    {
                        try
                        {
                        }
                        catch ( Exception ex )
                        {
                            LogWrapper.Logger.Error( ex );
                        }
                    } ) , false );//不允许任务重入
                }
                else
                {
                    TaskHandle.Start( );
                }
                return true;
            }
            else
            {
                DisposeTask( );
                return false;
            }
        }

        /// <summary>
        /// 销毁内存定时回收任务
        /// </summary>
        /// <returns></returns>
        protected override bool DisposeTask( )
        {
            if ( TaskHandle != null )
            {
                TaskHandle.Dispose( );
                TaskHandle = null;
                return true;
            }
            return false;
        }
    }
}